<template>
  <section class="product-section">
    <div class="container">
      <h2 class="section-title">热门产品推荐</h2>
      <div class="products-grid">
        <div 
          v-for="server in servers" 
          :key="server.id" 
          class="product-card"
        >
          <!-- 图标 -->
          <div class="product-icon">
            <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <rect x="2" y="2" width="20" height="8" rx="2" ry="2"></rect>
              <rect x="2" y="14" width="20" height="8" rx="2" ry="2"></rect>
              <line x1="6" y1="6" x2="6.01" y2="6"></line>
              <line x1="6" y1="18" x2="6.01" y2="18"></line>
            </svg>
          </div>

          <!-- 配置名称 -->
          <h3 class="product-name">{{ server.name }}</h3>

          <!-- 配置详情 -->
          <div class="product-specs">
            <div class="spec-item">
              <span class="spec-label">CPU</span>
              <span class="spec-value">{{ server.cpu.model }}</span>
            </div>
            <div class="spec-item">
              <span class="spec-label">内存</span>
              <span class="spec-value">{{ server.ram.size }}</span>
            </div>
            <div class="spec-item">
              <span class="spec-label">存储</span>
              <span class="spec-value">{{ server.storage.total }}</span>
            </div>
            <div class="spec-item">
              <span class="spec-label">带宽</span>
              <span class="spec-value">{{ server.network.bandwidth }}</span>
            </div>
            <div class="spec-item">
              <span class="spec-label">流量</span>
              <span class="spec-value">{{ server.network.transfer }}</span>
            </div>
          </div>

          <!-- 价格 -->
          <div class="product-footer">
            <div class="price" v-if="server.price">
              <span class="price-currency">¥</span>
              <span class="price-amount">{{ server.price }}</span>
              <span class="price-period">/月</span>
            </div>
            <button class="btn-buy">查看详情</button>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getPopularServers } from '../services/serverData'

// 从统一的数据源获取服务器配置
const servers = ref(getPopularServers())

// 如果需要，可以在这里添加异步数据加载
// onMounted(async () => {
//   servers.value = await fetchServersFromAPI()
// })
</script>

<style scoped>
.product-section {
  padding: 80px 20px;
  background: #f5f7fa;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
}

.section-title {
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  color: #1a1a1a;
  margin-bottom: 60px;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

.product-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 32px 24px;
  border: 1px solid #e5e7eb;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  border-color: #1e5cff;
  box-shadow: 0 8px 24px rgba(30, 92, 255, 0.12);
  transform: translateY(-4px);
}

.product-icon {
  color: #1e5cff;
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
}

.product-name {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 24px;
  text-align: center;
  min-height: 48px;
}

.product-specs {
  flex: 1;
  margin-bottom: 24px;
}

.spec-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}

.spec-item:last-child {
  border-bottom: none;
}

.spec-label {
  font-size: 14px;
  color: #6b7280;
  font-weight: 500;
}

.spec-value {
  font-size: 14px;
  color: #1a1a1a;
  font-weight: 500;
}

.product-footer {
  border-top: 1px solid #e5e7eb;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.price {
  text-align: center;
}

.price-currency {
  font-size: 18px;
  color: #1e5cff;
  font-weight: 600;
}

.price-amount {
  font-size: 32px;
  color: #1e5cff;
  font-weight: 700;
}

.price-period {
  font-size: 16px;
  color: #6b7280;
}

.btn-buy {
  width: 100%;
  padding: 12px 24px;
  background: #1e5cff;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-buy:hover {
  background: #1548cc;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 92, 255, 0.3);
}

@media (max-width: 768px) {
  .product-section {
    padding: 60px 20px;
  }

  .section-title {
    font-size: 28px;
    margin-bottom: 40px;
  }

  .products-grid {
    grid-template-columns: 1fr;
  }
}
</style>

